// 1 安装路由
// 2 导入router
import { patch } from 'request'
import Vue from 'vue'
import VueRouter from 'vue-router'
// 3 注册
Vue.use(VueRouter)
// 4 配置路由规则
import Home from '../views/Home.vue'
import details from '../views/details.vue'
import test from '../views/test.vue'

const routes = [
  { path: '/', name: 'home' ,component: Home },
  { path: '/details', name: 'details', component: details },
  { path: '/test', name: 'test', component: test },

]
//实例化
const router = new VueRouter({
  routes,
  // mode: 'history'
})



// router.beforeRouteLeave((to,from, next) => {
//   const scrollPosition = {
//     x: window.pageXOffset,
//     y: window.pageYOffset
//   }
//   from.meta.scrollPosition = scrollPosition
//   next(to)
//   })
//   addEventListener('popstate',() => {
//     router.go(-1)
//     const scrollPosition = router.currentRoute.meta.scrollPosition
//     if(scrollPosition){
//       setTimeout(() => {
//         window.scrollTo(scrollPosition.x,scrollPosition.y)
//       }, 0);
//     }
//   })

export default router